package com.ohs.ohsoa.system.controller;


import java.util.List;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.ohs.ohsoa.system.dto.OvertimesettingDto;
import com.ohs.ohsoa.system.entity.Overtimesetting;
import com.ohs.ohsoa.system.service.OvertimesettingService;
import com.ohs.ohsoa.utils.auth.UserLoginToken;
import com.ohs.ohsoa.utils.bean.requestBean.PageParam;
import com.ohs.ohsoa.utils.bean.responseBean.ResultBean;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 加班设置Controller
 *
 * @author qianjp
 *
 */
@RestController
@RequestMapping("/overtimesetting")
@Api(value = " 加班设置", tags = " 加班设置")
public class OvertimesettingController  {
    @Resource
    private OvertimesettingService overtimesettingService;

    /**
     * 获取加班列表信息
     **/
    @UserLoginToken
    @PostMapping(value = "/select/list")
    @ApiOperation(httpMethod = "POST", value = "获取加班列表信息")
    public ResultBean<PageInfo<Overtimesetting>> overtimesettingSelectList(@RequestBody PageParam<OvertimesettingDto> pageParam) {
        List<Overtimesetting> res = overtimesettingService.overtimesettingSelectList(pageParam);
        return ResultBean.success(new PageInfo<>(res));
    }

    /**
     * 根据id获取加班详细信息
     *
     * @param overtimesetting 加班详细信息数据
     * @return 加班详细信息
     *
     */
    @UserLoginToken
    @PostMapping(value = "/select")
    @ApiOperation(httpMethod = "POST", value = "根据id获取加班详细信息")
    public ResultBean<Overtimesetting> overtimesettingSelectById(@RequestBody Overtimesetting overtimesetting) {
        return ResultBean.success(overtimesettingService.overtimesettingSelectById(overtimesetting));
    }

    /**
     * 修改加班详细
     *
     * @param overtimesetting 加班详细信息数据
     * @return 修改结果
     */
    @UserLoginToken
    @PutMapping(value = "/update")
    @ApiOperation(httpMethod = "PUT", value = "修改加班详细")
    public ResultBean<Boolean> overtimesettingUpdate(@RequestBody @Valid Overtimesetting overtimesetting, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBean.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        return ResultBean.success(overtimesettingService.overtimesettingUpdate(overtimesetting));
    }
}
